package main

import (
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/client/selector"
	"github.com/micro/go-plugins/registry/etcdv3/v2"
	"gomicro/formJsonMicro/fjmMessage"
	_ "gomicro/formJsonMicro/fjmServer/dao"
	"gomicro/formJsonMicro/fjmServer/handler"
	"log"
	"math/rand"
	"strconv"

	"gomicro/formJsonMicro/fjmServer/util"
	"gomicro/formJsonMicro/fjmServer/wrappers"
	"gomicro/webGoMicro/webMessage"
)

func main() {

	//studentService
	studentService := micro.NewService(
		micro.Selector(selector.NewSelector(selector.Registry(etcdv3.NewRegistry()),
			selector.SetStrategy(selector.RoundRobin),)),
		micro.Registry(etcdv3.NewRegistry()),
		//micro.Registry(util.EtcdRegistry),
		micro.WrapClient(wrappers.NewLogWrapper),
		micro.WrapClient(wrappers.NewClientWrapper()),
	)

	util.Cli = webMessage.NewStudentService("student_micro_service", studentService.Client())

	//创建一个新的服务对象实例
	service := micro.NewService(
		micro.Name("member_micro_service"),
		micro.Version("v2.7.0"),
		micro.Registry(etcdv3.NewRegistry()),

		micro.WrapClient(wrappers.NewClientWrapper()),
	)

	//服务初始化
	service.Init()

	//注册
	hs := handler.MemberHandlerCuda{
		Tag :strconv.Itoa(rand.Int()),
	}
	fjmMessage.RegisterMemberServiceHandler(service.Server(), &hs)  //new(handler.StudentHandlerCuda)

	//运行
	err := service.Run()
	if err != nil {
		log.Fatal(err)
	}

}